//
//  MemberActivityAlertView.swift
//  funcode
//
//  Created by Wan Jiading on 2017/9/18.
//  Copyright © 2017年 WanJiading. All rights reserved.
//  会员活动提醒

///// 会员剩余到期时间描述,示例:您的金卡会员还有321天就到期啦!
//var memberLeftTimeDesc: String?
//
///// 优惠价剩余时间描述,示例:特惠价只剩10天哦!
//var discountsLeftTimeDesc: String?
//
///// 福利介绍
//var wealDesc: String?
//
///// 按钮文本
//var buttonText: String?
//
///// 价格图片url
//var picUrl: String?

import UIKit

class MemberActivityAlertView: BaseAlertView {

//     var memberActivityModel: MemberActivityModel?
    
    convenience init(_ memberActivityModel: MemberActivityModel) {
        self.init()
        beforeSetupSubViews()
        
        setupContentSize(CGSize(width: 300, height: 400))
        
        // 1. 背景图
        let bgImageView = UIImageView(image: UIImage(named: "member_activity_bg"))
        contentView.addSubview(bgImageView)
        bgImageView.snp.makeConstraints { (make) in
            make.edges.equalTo(contentView).inset(UIEdgeInsets.zero)
        }
        
        // 2. title
        let titleLabel = UILabel()
        contentView.addSubview(titleLabel)
        titleLabel.text = memberActivityModel.title
        titleLabel.textAlignment = .center
        titleLabel.font = UIFont.boldSystemFont(ofSize: 30)
        titleLabel.textColor = UIColor.white
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.top.equalTo(contentView.snp.top).offset(45)
            make.height.equalTo(42)
        }
        
        // 3. 会员到期时间
        let memberLeftTimeDescLabel = UILabel()
        contentView.addSubview(memberLeftTimeDescLabel)
        memberLeftTimeDescLabel.text = memberActivityModel.memberLeftTimeDesc
        memberLeftTimeDescLabel.textAlignment = .center
        memberLeftTimeDescLabel.font = UIFont.boldSystemFont(ofSize: 12)
        memberLeftTimeDescLabel.textColor = UIColor.rgb("e6e6e6")
        memberLeftTimeDescLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.top.equalTo(titleLabel.snp.bottom)
        }
        
        // 4. 价格图片
        let priceImageView = UIImageView()
        priceImageView.image = UIImage(named: "member_activity_price")
        contentView.addSubview(priceImageView)
        priceImageView.snp.makeConstraints { (make) in
            make.left.equalTo(contentView.snp.left).offset(69)
            make.top.equalTo(memberLeftTimeDescLabel.snp.bottom).offset(41)
            make.height.equalTo(104)
        }
        
        // 5. 优惠还剩时间 TODO
        let discountsLeftTimeDescLabel = UILabel()
        contentView.addSubview(discountsLeftTimeDescLabel)
        discountsLeftTimeDescLabel.text = memberActivityModel.discountsLeftTimeDesc
        discountsLeftTimeDescLabel.textAlignment = .center
        discountsLeftTimeDescLabel.font = UIFont.boldSystemFont(ofSize: 12)
        discountsLeftTimeDescLabel.sizeToFit()
        discountsLeftTimeDescLabel.textColor = UIColor.rgb("e6e6e6")
        discountsLeftTimeDescLabel.clipsToBounds = true
        discountsLeftTimeDescLabel.layer.cornerRadius = 12.5
        let discountsLeftTimeDescWidth: CGFloat = discountsLeftTimeDescLabel.width + 12
        let discountsLeftTimeDescHeight: CGFloat = 22.5
        discountsLeftTimeDescLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.top.equalTo(priceImageView.snp.bottom).offset(27)
            make.width.equalTo(discountsLeftTimeDescWidth)
            make.height.equalTo(discountsLeftTimeDescHeight)
        }
        
        discountsLeftTimeDescLabel.backgroundColor = UIColor.gradient([UIColor.rgb("594fd8"),
                                                                       UIColor.rgb("a970ff")],
                                                                      GuadientType.rightTopToLeftBottom,
                                                                      CGSize(width: discountsLeftTimeDescWidth, height: discountsLeftTimeDescHeight))
        
        // 6. 福利介绍 TODO
        let wealDescLabel = UILabel()
        contentView.addSubview(wealDescLabel)
        wealDescLabel.text = memberActivityModel.wealDesc
        wealDescLabel.textAlignment = .center
        wealDescLabel.font = UIFont.boldSystemFont(ofSize: 12)
        wealDescLabel.textColor = UIColor.rgb("fdfd01")
        wealDescLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.top.equalTo(discountsLeftTimeDescLabel.snp.bottom).offset(6)
        }
        
        // 7. 按钮
        let okBtn = UIButton(type: .custom)
        contentView.addSubview(okBtn)
        okBtn.setTitle(memberActivityModel.buttonText, for: .normal)
        okBtn.setTitleColor(UIColor.rgb("3d2ccd"), for: .normal)
        okBtn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        okBtn.sizeToFit()
        okBtn.clipsToBounds = true
        okBtn.layer.cornerRadius = 6
        let okBtnWidth = 162
        let okBtnHeight = 37
        okBtn.snp.makeConstraints { (make) in
            make.centerX.equalTo(contentView)
            make.bottom.equalTo(contentView.snp.bottom).offset(-15)
            make.height.equalTo(okBtnHeight)
            make.width.equalTo(okBtnWidth)
        }
        okBtn.backgroundColor = UIColor.gradient([UIColor.rgb("fcff00"),
                                                  UIColor.rgb("fdd90a")],
                                                 GuadientType.leftTopToRightBottom,
                                                 CGSize(width: okBtnWidth, height: okBtnHeight))
        
        okBtn.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
        
        // 8. 猫
        let catImageView = UIImageView(image: UIImage(named: "member_activity_cat"))
        contentView.addSubview(catImageView)
        catImageView.sizeToFit()
        catImageView.snp.makeConstraints { (make) in
            make.right.equalTo(contentView.snp.right).offset(-6)
            make.bottom.equalTo(contentView.snp.bottom).offset(-12)
        }
        
        afterSetupSubviews()
    }
    
    func btnClick() {
        
    }
    
}
